local xingqi = fk.CreateSkill{
  name = "bd__xingqi",
}

Fk:loadTranslationTable{
  ["bd__xingqi"] = "星启",
  [":bd__xingqi"] = "你使用与上一张判定牌花色相同的牌后可以摸一张牌并进行一次【闪电】判定。",
}

xingqi:addEffect(fk.CardUseFinished, {
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(xingqi.name) then return end
    local judgeEvent = player.room.logic:getEventsByRule(GameEvent.Judge, 1, function (e)
      return e.data.card ~= nil
    end, -1, Player.HistoryGame)
    if #judgeEvent > 0 then
      return data.card.suit == judgeEvent[1].data.card.suit
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:drawCards(1, xingqi.name)
    local judge = JudgeData:new {
      who = player,
      reason = "lightning",
      pattern = ".|2~9|spade",
    }
    room:judge(judge)
    if judge:matchPattern() then
      room:damage{
        to = player,
        damage = 3,
        damageType = fk.ThunderDamage,
        skillName = "lightning_skill",
      }
    end
  end
})

return xingqi